import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * @author soffo
 *
 */
public class VideoCopyModel {

	private Integer videoCopyNumber;
	private String title;
	private String category;
	private Date releaseDate = new Date();
	private Integer numOfCopies;
	private Boolean checkOut;
	private Double price;

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Boolean isCheckOut() {
		return checkOut;
	}

	public void setCheckOut(Boolean checkOut) {
		this.checkOut = checkOut;
	}

	public VideoCopyModel() {
		// TODO Auto-generated constructor stub
	}

	public Integer getVideoCopyNumber() {
		return videoCopyNumber;
	}

	public void setVideoCopyNumber(Integer videoCopyNumber) {
		this.videoCopyNumber = videoCopyNumber;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	public Integer getNumOfCopies() {
		return numOfCopies;
	}

	public void setNumOfCopies(Integer numOfCopies) {
		this.numOfCopies = numOfCopies;
	}



	@Override
	public String toString() {
		return "VideoCopyRecord [videoCopyNumber=" + videoCopyNumber
				+ ", title=" + title + ", category=" + category
				+ ", releaseDate=" + releaseDate + ", numOfCopies="
				+ numOfCopies + ", checkOut=" + checkOut + ", price=" + price
				+ "]";
	}

	public ArrayList<VideoCopyModel> findMovieByNumber(Integer CopyNumber,
			ArrayList<VideoCopyModel> movies) {

		ArrayList<VideoCopyModel> moviesTemp = new ArrayList<>();
		for (VideoCopyModel movie : movies) {
			if (movie.getVideoCopyNumber() == CopyNumber) {
				moviesTemp.add(movie);
			}

		}

		return moviesTemp;
	}

	public ArrayList<VideoCopyModel> deleteMovieByNumber(Integer CopyNumber, ArrayList<VideoCopyModel> movies) {

		VideoCopyModel videoCopyModel;
		Iterator itr = movies.iterator();

		while (itr.hasNext()) {
			videoCopyModel = new VideoCopyModel();
			videoCopyModel = (VideoCopyModel) itr.next();
			if (videoCopyModel.getVideoCopyNumber() == CopyNumber) {
				itr.remove();
			}
		}

		return movies;
	}

	public ArrayList<VideoCopyModel> updateMoviesCollection( ArrayList<VideoCopyModel> videoCopyModels, VideoCopyModel videoCopyModelParam)
	{
		VideoCopyModel videoCopyModel;
		Iterator itr = videoCopyModels.iterator();
		int i = 0;
		while (itr.hasNext()) {
			videoCopyModel = new VideoCopyModel();
			videoCopyModel = (VideoCopyModel) itr.next();
			if (videoCopyModel.getVideoCopyNumber() == videoCopyModelParam.getVideoCopyNumber()) {
				videoCopyModels.set(i, videoCopyModelParam);
			}
			i++;
		}

		return videoCopyModels;
	}
}
